import BasePageCtrl, { AnimType } from "./BasePageCtrl";
import PageMgr from "./PageMgr";
import ClockSuccessToastPage from "./ClockSuccessToastPage";
const { ccclass, property } = cc._decorator;

@ccclass
export default class ClockSuccessToastPageCtrl extends BasePageCtrl {
    @property(cc.Node)
    ui = null;


    static prefabUrl = "ClockSuccessToastPage";
    static className = "ClockSuccessToastPageCtrl";

    onLoad() {
        super.onLoad();
        this.onUILoad();
        this._animType = AnimType.SCALE;
        this._touchControl = false;
        this._hasPeneLock = true;
        this._hasBlack = false;
        this._hasTouchLock = false;
        this._hasBlackTouch = false;
        this._reuse = false;
        BasePageCtrl.prototype.onLoad.call(this);
        this.addButtonListen();
    }

    start() {}

    onUILoad() {
        this.ui = this.node.addComponent(ClockSuccessToastPage);
        cc.tween(this.ui.bg)
            .delay(2)
            .to(1, { opacity: 0 })
            .call(() => {
                this.playHbFlyAni();
            })
            .start();
    }

    playHbFlyAni() {
        for (let i = 0; i < 10; i++) {
            let rewardNode = cc.instantiate(this.ui.reward);
            rewardNode.opacity = 255;
            rewardNode.parent = this.node;
            rewardNode.position = cc.v3(0, 350);
            this.playFlyToCentenAni(rewardNode, i);
        }
    }

    playFlyToCentenAni(node, index) {
        cc.tween(node)
            .delay(index / 10)
            .to(0.5, { position: cc.v3(-130, 150) })
            .delay(0.2)
            .call(() => {
                if (index === 9) {
                    this.clickClose();
                }
                node.active = false;
            })
            .start();
    }

    addButtonListen() {}

    clickClose() {
        PageMgr.showPage("OutsideBeiJingGuidePage");
        this.hide();
    }
}

